<!DOCTYPE html>
<html>
    <head>
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'product.label', default: 'Product')}" />
        <title>产品：${this.product.name}</title>
    </head>
    <body class="fixed-navbar fixed-sidebar">
        <div class="small-header">
            <div class="hpanel">
                <div class="panel-body">
                    <div id="hbreadcrumb" class="pull-right">
                        <ol class="hbreadcrumb breadcrumb">
                            <li>Cake Store</li>
                            <li><g:link controller="product" action="index">产品管理</g:link></li>
                            <li class="active">
                                <span>${this.product.name}</span>
                            </li>
                        </ol>
                    </div>

                    <h2 class="font-light m-b-xs" style="text-transform:none;">
                        产品: ${this.product.name}
                    </h2>
                </div>
            </div>
        </div>

        <div class="content animate-panel">
            <g:if test="${flash.message}">
                <div class="message alert alert-info" role="status">${flash.message}
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
                </div>
            </g:if>
            <g:hasErrors bean="${this.product}">
                <ul class="errors" role="alert">
                    <g:eachError bean="${this.product}" var="error">
                        <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message
                                error="${error}"/></li>
                    </g:eachError>
                </ul>
            </g:hasErrors>

            <div class="hpanel hblue row">
                <div class="panel-heading">
                    <div class="panel-tools">
                        <g:link class="btn btn-info btn-xs" action="edit" resource="${this.product}" id="${this?.product?.id}"><i class="fa fa-edit"></i>编辑</g:link>
                        <a class="showhide"><i class="fa fa-chevron-up"></i></a>
                    </div>
                    产品详情
                </div>

                <div class="panel-body form-horizontal">
                    <div class="form-group">
                        <label class="col-md-2 control-label">名称</label>

                        <div class="col-md-3">
                            <p class="form-control-static">${this.product?.name}</p>
                        </div>
                        
                         <label class="col-md-2 control-label">有效性</label>

                        <div class="col-md-3">
                            <p class="form-control-static">${this.product?.active ? '是' : '否'}</p>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label">类型</label>

                        <div class="col-md-3">
                            <p class="form-control-static">${this.product?.type?.name}</p>
                        </div>

                        <label class="col-md-2 control-label">单价</label>

                        <div class="col-md-3">
                            <p class="form-control-static">${this.product?.price} 元</p>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label">主图片</label>
                        <div class="col-md-3">
                            <g:if test="${this.product?.imageUrl}">
                                <p class="form-control-static">${this.product?.imageUrl}</p>
                            </g:if>
                            <g:else>
                                <p style="color: red" class="form-control-static">请添加产品图片，并设置主图片</p>
                            </g:else>
                        </div>

                        <g:if test="${this.product?.type?.allowAddSize}">
                            <label class="col-md-2 control-label">尺寸</label>
                            <g:if test="${this.product?.productItem}">
                                <div class="col-md-3">
                                    <p class="form-control-static">${this.product?.productItem?.size} 寸</p>
                                </div>
                            </g:if>
                            <g:else>
                                <div class="col-md-3">
                                    <p class="form-control-static" style="color: red">请添加产品规格，并设置默认产品</p>
                                </div>
                            </g:else>
                        </g:if>
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label">描述</label>

                        <div class="col-md-8">
                            <p class="form-control-static">${this.product?.description}</p>
                        </div>
                    </div>
                </div>
            </div>

            <div class="hpanel hyellow row">
                <div class="panel-heading">
                    <div class="panel-tools">
                        <g:link class="btn btn-xs btn-info" controller="attachment" action="create" params="[product: this.product?.id]"><i class="fa fa-plus"></i>新增</g:link>
                        <a class="showhide"><i class="fa fa-chevron-up"></i></a>
                    </div>
                    产品图片
                </div>
                <g:render template="/layouts/template/attachmentTemplate"/>
            </div>
                
            <g:if test="${this.product?.type?.allowAddSize}">
                <div class="hpanel hblue row">
                    <div class="panel-heading">
                        <div class="panel-tools">
                            <g:link class="btn btn-xs btn-info" controller="productItem" action="create" params="[product: this.product?.id]"><i class="fa fa-plus"></i>新增</g:link>
                            <a class="showhide"><i class="fa fa-chevron-up"></i></a>
                        </div>
                        产品规格
                    </div>

                    <div class="panel-body no-padding">
                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover text-center">
                                <thead>
                                <tr>
                                    <g:sortableColumn property="productItem.size" title="尺寸"></g:sortableColumn>
                                    <g:sortableColumn property="productItem.price" title="价格"></g:sortableColumn>
                                    <g:sortableColumn property="productItem.range" title="规格"></g:sortableColumn>
                                    <g:sortableColumn property="productItem.freight" title="运费"></g:sortableColumn>
                                    <g:sortableColumn property="productItem.description" title="描述"></g:sortableColumn>
                                    <g:sortableColumn property="productItem.active" title="有效性"></g:sortableColumn>
                                    <g:sortableColumn  class="text-center" width="10%" colspan="2" property="active" title="操作"/>
                                </tr>
                                </thead>
                                <tbody>
                                <g:each in="${com.next.ProductItem.findAllByProduct(this.product)}">
                                    <tr>
                                        <td><g:link controller="productItem" action="edit" id="${it.id}" class="firstTd btn ${this.product?.productItem?.id == it?.id ? 'btn-success' : ''} btn-xs}">${it?.size}寸</g:link></td>
                                        <td>${it?.price}元</td>
                                        <td>${it?.range}</td>
                                        <td>${it?.freight}元</td>
                                        <td>${it?.description}</td>
                                        <td>${it?.active ? '是' : '否'}</td>
                                        <td class="text-center">
                                            <g:form controller="product" action="setToMainProduct" id="${it?.id}">
                                                <button class="confirmBtn btn btn-xs btn-link" type="button"><i class="fa fa-edit"></i></i> 设置为默认产品</button>
                                            </g:form>
                                        </td>
                                        <td class="text-center">
                                            <g:form controller="product" action="changeActive" id="${it?.id}">
                                                <button class="confirmBtn btn btn-xs btn-link" type="button"><i class="fa fa-trash-o"></i> ${it?.active ? '失效' : '生效'}</button>
                                            </g:form>
                                        </td>
                                    </tr>
                                </g:each>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </g:if>
        </div>
    </body>
</html>
